
CREATE OR REPLACE TRIGGER ENTRIES_UPDATE_HISTORY AFTER UPDATE OR DELETE OR INSERT
  ON A_C_ACCOUNTING_ENTRIES FOR EACH ROW
  DECLARE
    EVENT_TYPE1 A_C_ACCOUNTING_ENTRIES_HISTORY.EVENT_TYPE%TYPE;
    EVENT_TIME1 A_C_ACCOUNTING_ENTRIES_HISTORY.EVENT_TIME%TYPE;
  BEGIN
    EVENT_TIME1 := sysdate;
    IF INSERTING THEN
      EVENT_TYPE1 := 'INSERTED';
      INSERT INTO A_C_ACCOUNTING_ENTRIES_HISTORY(
          ID, EVENT_TYPE, EVENT_TIME, NEW_CONSIGN_HISTORY_ID, NEW_CONS_NO, NEW_TYPE, NEW_CURR_CODE, NEW_ACCOUNT,
          NEW_MAPPING_CODE, NEW_MAIN_SUBJECT, NEW_MAIN_SUBJECT_DESCRIPTION, NEW_SUB_SUBJECT, NEW_SUB_SUBJECT_DESCRIPTION,
          NEW_JOURNAL_NAME, NEW_SYS_CODE, NEW_ORG_SEGMENT, NEW_ORG_SNAME, NEW_ORG_FOUR_CODE, NEW_PLATE_SEGMENT,
          NEW_BACKUP_SEGMENT, NEW_PROJECT_SEGMENT, NEW_SUMMARY_CONTENT, NEW_GROUP_SEGMENT, NEW_GROUP_NAME,
          NEW_CONTACTS_SEGMENT, NEW_CONTACTS_NAME, NEW_SUBJECT_TYPE, CREATE_BY, CREATE_TIME, MODIFY_BY, MODIFY_TIME)
      VALUES (SEQ_GENERAL_ID.nextval, EVENT_TYPE1, EVENT_TIME1, :NEW.CONSIGN_HISTORY_ID, :NEW.CONS_NO, :NEW.TYPE, :NEW.CURR_CODE,
                 :NEW.ACCOUNT, :NEW.MAPPING_CODE, :NEW.MAIN_SUBJECT, :NEW.MAIN_SUBJECT_DESCRIPTION, :NEW.SUB_SUBJECT,
                 :NEW.SUB_SUBJECT_DESCRIPTION, :NEW.JOURNAL_NAME, :NEW.SYS_CODE, :NEW.ORG_SEGMENT, :NEW.ORG_SNAME,
                 :NEW.ORG_FOUR_CODE, :NEW.PLATE_SEGMENT, :NEW.BACKUP_SEGMENT, :NEW.PROJECT_SEGMENT, :NEW.SUMMARY_CONTENT,
                 :NEW.GROUP_SEGMENT, :NEW.GROUP_NAME, :NEW.CONTACTS_SEGMENT, :NEW.CONTACTS_NAME, :NEW.SUBJECT_TYPE,
                 :NEW.CREATE_BY, :NEW.CREATE_TIME, :NEW.MODIFY_BY, :NEW.MODIFY_TIME);
    ELSIF UPDATING THEN
      IF (:NEW.REMOVED = 1) THEN
        EVENT_TYPE1 := 'DELETED';
      ELSE EVENT_TYPE1 := 'UPDATED';
      end if;
        INSERT INTO A_C_ACCOUNTING_ENTRIES_HISTORY(
            ID, EVENT_TYPE, EVENT_TIME, OLD_ID, OLD_CONSIGN_HISTORY_ID, OLD_CONS_NO, OLD_TYPE, OLD_CURR_CODE, OLD_ACCOUNT,
            OLD_MAPPING_CODE, OLD_MAIN_SUBJECT, OLD_MAIN_SUBJECT_DESCRIPTION, OLD_SUB_SUBJECT, OLD_SUB_SUBJECT_DESCRIPTION,
            OLD_JOURNAL_NAME, OLD_SYS_CODE, OLD_ORG_SEGMENT, OLD_ORG_SNAME, OLD_ORG_FOUR_CODE, OLD_PLATE_SEGMENT,
            OLD_BACKUP_SEGMENT, OLD_PROJECT_SEGMENT, OLD_SUMMARY_CONTENT, OLD_GROUP_SEGMENT, OLD_GROUP_NAME,
            OLD_CONTACTS_SEGMENT, OLD_CONTACTS_NAME, OLD_SUBJECT_TYPE, NEW_CONSIGN_HISTORY_ID, NEW_CONS_NO, NEW_TYPE,
            NEW_CURR_CODE, NEW_ACCOUNT, NEW_MAPPING_CODE, NEW_MAIN_SUBJECT, NEW_MAIN_SUBJECT_DESCRIPTION, NEW_SUB_SUBJECT,
            NEW_SUB_SUBJECT_DESCRIPTION, NEW_JOURNAL_NAME, NEW_SYS_CODE, NEW_ORG_SEGMENT, NEW_ORG_SNAME, NEW_ORG_FOUR_CODE,
            NEW_PLATE_SEGMENT, NEW_BACKUP_SEGMENT, NEW_PROJECT_SEGMENT, NEW_SUMMARY_CONTENT, NEW_GROUP_SEGMENT, NEW_GROUP_NAME,
            NEW_CONTACTS_SEGMENT, NEW_CONTACTS_NAME, NEW_SUBJECT_TYPE, CREATE_BY, CREATE_TIME, MODIFY_BY, MODIFY_TIME)
        VALUES (
                SEQ_GENERAL_ID.nextval, EVENT_TYPE1, EVENT_TIME1, :OLD.ID, :OLD.CONSIGN_HISTORY_ID, :OLD.CONS_NO, :OLD.TYPE,
                :OLD.CURR_CODE, :OLD.ACCOUNT, :OLD.MAPPING_CODE, :OLD.MAIN_SUBJECT, :OLD.MAIN_SUBJECT_DESCRIPTION,
                :OLD.SUB_SUBJECT, :OLD.SUB_SUBJECT_DESCRIPTION, :OLD.JOURNAL_NAME, :OLD.SYS_CODE, :OLD.ORG_SEGMENT, :OLD.ORG_SNAME,
                :OLD.ORG_FOUR_CODE, :OLD.PLATE_SEGMENT, :OLD.BACKUP_SEGMENT, :OLD.PROJECT_SEGMENT, :OLD.SUMMARY_CONTENT,
                :OLD.GROUP_SEGMENT, :OLD.GROUP_NAME, :OLD.CONTACTS_SEGMENT, :OLD.CONTACTS_NAME, :OLD.SUBJECT_TYPE,
                :NEW.CONSIGN_HISTORY_ID, :NEW.CONS_NO, :NEW.TYPE,
                :NEW.CURR_CODE, :NEW.ACCOUNT, :NEW.MAPPING_CODE, :NEW.MAIN_SUBJECT, :NEW.MAIN_SUBJECT_DESCRIPTION,
                :NEW.SUB_SUBJECT, :NEW.SUB_SUBJECT_DESCRIPTION, :NEW.JOURNAL_NAME, :NEW.SYS_CODE, :NEW.ORG_SEGMENT, :NEW.ORG_SNAME,
                :NEW.ORG_FOUR_CODE, :NEW.PLATE_SEGMENT, :NEW.BACKUP_SEGMENT, :NEW.PROJECT_SEGMENT, :NEW.SUMMARY_CONTENT,
                :NEW.GROUP_SEGMENT, :NEW.GROUP_NAME, :NEW.CONTACTS_SEGMENT, :NEW.CONTACTS_NAME, :NEW.SUBJECT_TYPE,
                :NEW.MODIFY_BY, :NEW.MODIFY_TIME, :NEW.MODIFY_BY, :NEW.MODIFY_TIME);
    end if;
  END;